import { setToken, setUserInfo } from '@/utils'
import { login } from '@/api/user'

export default {
  namespaced: true,
  state: {
    token: '',
    userInfo: {}
  },
  getters: {},
  mutations: {
    setToken(state, token) {
      state.token = token
      setToken(token)
    },
    setUserInfo(state, info) {
      state.userInfo = info
      setUserInfo(info)
    }
  },
  actions: {
    handleLogin({ commit }) {
      return login().then(res => {
        commit('setToken', res.data.data.token)
        commit('setUserInfo', res.data.data.userInfo)
        return res
      })
    },
    handleLogout({ commit }) {

    }
  }
}
